from django.contrib import admin
from .models import Host, ConnectionRecord, CommandLog, Alert


@admin.register(Host)
class HostAdmin(admin.ModelAdmin):
    list_display = ('hostname', 'public_ip', 'private_ip', 'port', 'type', 'status', 'created_at', 'updated_at')
    list_filter = ('type', 'status')
    search_fields = ('hostname', 'public_ip', 'private_ip')
    readonly_fields = ('created_at', 'updated_at')


@admin.register(ConnectionRecord)
class ConnectionRecordAdmin(admin.ModelAdmin):
    list_display = ('user', 'host', 'connected_at', 'disconnected_at', 'is_active', 'command_count')
    list_filter = ('is_active', 'user')
    search_fields = ('host__hostname', 'host__public_ip', 'host__private_ip', 'user__username')
    readonly_fields = ('connected_at', 'disconnected_at')


@admin.register(CommandLog)
class CommandLogAdmin(admin.ModelAdmin):
    list_display = ('connection', 'command', 'executed_at')
    list_filter = ('executed_at',)
    search_fields = ('command', 'connection__host__hostname')
    readonly_fields = ('executed_at',)


@admin.register(Alert)
class AlertAdmin(admin.ModelAdmin):
    list_display = ('title', 'host', 'level', 'is_read', 'created_at')
    list_filter = ('level', 'is_read')
    search_fields = ('title', 'content', 'host__hostname')
    readonly_fields = ('created_at',) 